package com.colabo.j2ee.web.oaf.security.encoder;

import org.springframework.security.authentication.encoding.MessageDigestPasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;

/**
 * ��(SHA)������
 */
public class SHAPasswordEncoder extends MessageDigestPasswordEncoder implements IPasswordEncoder {
	/**
	 * Initializes the ShaPasswordEncoder for SHA-1 strength
	 */
	public SHAPasswordEncoder() {
		this(1);
	}

	public String encode(String pwd) {
		return encodePassword(pwd, "");
	}

	/**
	 * Initialize the ShaPasswordEncoder with a given SHA stength as supported
	 * by the JVM EX:
	 * <code>ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);</code>
	 * initializes with SHA-256
	 * 
	 * @param strength
	 *            EX: 1, 256, 384, 512
	 */
	public SHAPasswordEncoder(int strength) {
		super("SHA-" + strength);
	}
	
	public String encodePassword(String rawPass, Object salt){
        ShaPasswordEncoder sha = new ShaPasswordEncoder();    
        sha.setEncodeHashAsBase64(true);     
		return sha.encodePassword(rawPass, null);
	}
}
